package org.fujay.langchain4jserver.domain.knowledge.vo;

import lombok.Getter;

/**
 * 知识库聚合状态枚举
 */
@Getter
public enum KnowledgeBaseStatus {
    EMPTY(0, "空/无文件"),
    INDEXING_PARTIAL(1, "部分文件索引中"),
    INDEXING_COMPLETED(2, "索引完成"),
    INDEXING_FAILED(3, "索引失败"),
    INDEXING_FULL(4, "全量索引中"),
    NEEDS_REINDEX(5, "需要重建索引"); // 可选状态，用于模型变更等情况

    private final int code;
    private final String description;

    KnowledgeBaseStatus(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public static KnowledgeBaseStatus fromCode(int code) {
        for (KnowledgeBaseStatus status : KnowledgeBaseStatus.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown KnowledgeBaseStatus code: " + code);
    }

    // 判断是否处于索引过程中
    public boolean isIndexing() {
        return this == INDEXING_PARTIAL || this == INDEXING_FULL;
    }

    // 判断是否处于空闲状态（可以添加文件或触发索引）
    public boolean isIdle() {
        return this == EMPTY
                || this == INDEXING_COMPLETED
                || this == INDEXING_FAILED
                || this == NEEDS_REINDEX;
    }
}
